Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for re-generating endpoints without restart #1146

Merged
merged 22 commits into from
Aug 24, 2023

Conversation

taefi
Copy link
Contributor

@taefi taefi commented Aug 16, 2023

Description

This feature is based on having either HotSwap Agent or JRebel set in the development environment for
reloading classes so that Parser and Generator can re-generate the needed TS files based on the latest compiled classes.

In this approach, an initiated service at startup polls for the changes of the endpoints and their associated classes, and by comparing the openapi contents with the previous state it will regenerate the needed TS files which makes them available to the views without restarting the application.

The polling service will start monitoring the changes (in a separate thread) if:

  • Application is running in Dev mode, and
  • Dev mode live reload is enabled, and
  • The backend support for live reload is not Spring Boot DevTools

When a development environment meet the above criteria, the hot-reload feature is enabled by default. However, it can be disabled by setting the following property to false:

  • hilla.endpoint.hot-reload.enabled

The default monitoring poll interval is 5 seconds, which is configurable by setting the following property:

  • hilla.endpoint.hot-reload.pollInterval

Limitations:
The limitations are dictated by the limitations of JRebel or HotSwapAgent to redefining the classes at runtime. Some preliminary local tests shows that HotSwapAgent is working much smoother than JRebel. For example, JRebel sometimes fails to redefine the method renames in the memory, although, Hilla is reloading the change based on the latest changes completely fine. HowSwapAgent shows a faster reload as well compared to JRebel.

If Only Spring Boot DevTools is in use in an application, the watch service will not register for changes, so the developer experience will not change.

Developer, do not need to do any setup or changes to their project in order to enable this feature, other than setting up the HotSwapAgent or JRebel in their development environment.

Fixes #863

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

taefi and others added 8 commits June 30, 2023 22:02
This feature is based on having either HotSwap Agent
or JRebel set in the development environment for
reloading classes so that Parser and Generator can
re-generate the needed ts files based on the latest
compiled classes.

In this approach, a filesystem WatchService will start
monitoring the classes directory (in a separate thread)
for changes if:

- Application is running in Dev mode, and
- Dev mode live reload is enabled, and
- The backend support for live reload is not Spring Boot DevTools

When a change in the classes is detected, the Parser and
then Generator will update the openapi.json, and since
this file reside under classes itself, then its changes
also detected which will trigger the re-registration of
the Endpoints, without a need to restart the application.

Limitations:
The limitations are dictated by the limitations of JRebel
or HotSwapAgent to redefining the classes at runtime. Some
preliminary local tests shows that HotSwapAgent is working
much smoother than JRebel. For example, JRebel sometimes
fails to redefine the method renames in the memory, although,
Hilla is reloading the change based on the latest changes
completely fine. HowSwapAgent shows a faster reload as well
compared to JRebel.

If Only Spring Boot DevTools is in use in an application,
the watch service will not register for changes, so the
developer experience will not change.

Developer, do not need to do any setup or changes to their
project in order to enable this feature, other than setting
up the HotSwapAgent or JRebel in their development environment.
@taefi taefi requested a review from cromoteca August 16, 2023 13:17
@codecov
Copy link

codecov bot commented Aug 16, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (3f790ea) 96.49% compared to head (394c53a) 96.49%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1146   +/-   ##
=======================================
  Coverage   96.49%   96.49%           
=======================================
  Files          14       14           
  Lines        1657     1657           
  Branches      138      138           
=======================================
  Hits         1599     1599           
  Misses         58       58           
Flag Coverage Δ
unittests 96.49% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@taefi taefi requested a review from Artur- August 18, 2023 07:59
@platosha platosha enabled auto-merge (squash) August 22, 2023 11:41
@taefi taefi disabled auto-merge August 22, 2023 11:42
Artur- added a commit that referenced this pull request Aug 22, 2023
@taefi taefi enabled auto-merge (squash) August 22, 2023 11:44
Artur- added a commit that referenced this pull request Aug 22, 2023
@Artur- Artur- enabled auto-merge (squash) August 24, 2023 07:53
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Artur- Artur- merged commit 56b255b into main Aug 24, 2023
@Artur- Artur- deleted the feat/endpoint-polling branch August 24, 2023 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the Hotswap / JRebel Sync for Endpoints and Typescript generation
5 participants